var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var htmlmin = require('gulp-htmlmin');
// var rename = require('gulp-rename');
var connect = require('gulp-connect');
var clean = require('gulp-clean-css');
//操作sass
// gulp.task('css', function(){
// 	return sass('./src/sass/*.scss').pipe(gulp.dest('./src/style/'));
// });
//压缩css
	gulp.task('sass',function(){
	return sass('./src/sass/*.scss',{style:'compressed'}).pipe(gulp.dest('./dist/style/'));
});
//压缩js
gulp.task('js',function(){
	return gulp.src('./src/js/*.js').pipe(uglify()).pipe(gulp.dest('./dist/js/'));
});
//合并js文件
gulp.task('concat',function(){
	return gulp.src('./src/js/*.js').pipe(concat('all.js')).pipe(uglify()).pipe(gulp.dest('./dist/alljs/'));
});
//合并css文件
gulp.task('concatCSS',function(){
	return gulp.src('./dist/style/*.css').pipe(concat('all.css')).pipe(clean({rebase: false})).pipe(gulp.dest('./dist/allcss/'));
});
//压缩html文件
gulp.task('html',function(){
	return gulp.src('./*.html').pipe(htmlmin({collapseWhitespace: true})).pipe(gulp.dest('./dist/htmlmin/'));
});
//自动刷新
gulp.task('reload',['sass','js','concat','html','concatCSS'],function(){
	return gulp.src('./*.html').pipe(connect.reload());
});
//新建默认任务	
gulp.task('default',['sass','js','concat','html','concatCSS'],function(){
	//开启服务器
	connect.server({
		livereload:true
	});
	//监听命令
	gulp.watch(['./src/sass/*.scss','./src/style/*.css','./*.html','./src/js/*.js'],['reload']);
});


